﻿
using MODEL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class UserDAL
    {
        public UserDAL(MyContext context)
        {
            Context = context;
        }

        public MyContext Context { get; }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public int AddUser(User user)
        {
            try
            {
                Context.Users.Add(user);
                return Context.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public dynamic showUser(int index,int size)
        {
            try
            {
                var m = Context.Users.AsQueryable();
                int c=m.Count();
                var d=m.OrderByDescending(x=>x.Id).Skip((index-1)*size).Take(size).ToList();

                var res = new
                {
                    count= c,
                    data=d
                };
                return res;

            }
            catch (Exception)
            {

                throw;
            }
        }

        public List<User> GetUsers()
        {
           return Context.Users.ToList();
        }




    }
}
